<?php

if (! defined ( 'BASEPATH' ))
	exit ( 'No direct script access allowed' );

class Model_Global extends CI_Model {

	public function __construct() {
		parent::__construct ();
		require(APPPATH.'config/database.php');
		$this->load->database ( ACTIVE_COMPETITION );
	}
	
	public function get_user_competition_data($userid) {
		$sql = "SELECT userid, cover_gril_count, cover_gril_best_ranking, cover_gril_best_score, cover_gril_gold, cover_gril_silver, 
				cover_gril_bronze, pk_count, pk_best_ranking, pk_best_score, pk_gold, pk_silver, pk_bronze
				FROM user WHERE userid = $userid ";
		$query = $this->db->query ( $sql );
		if ($query->num_rows() > 0) {
			return $query->row(0);
		}
		else {
			return null;
		}
	}
	
	public function get_cg_update_data($userid) {
		$sql = "SELECT period, number_vote, number_weak, ranking FROM cover_gril WHERE userid = $userid ";
		$query = $this->db->query ( $sql );
		if ($query->num_rows() > 0) {
			return $query->row(0);
		}
		else {
			return null;
		}
	}
	
	public function get_pk_update_data($userid) {
		$sql = "SELECT period, pk_count, pked_count, pked_success, pked_failed, score, ranking FROM pk where userid = $userid ";
		$query = $this->db->query ( $sql );
		if ($query->num_rows() > 0) {
			return $query->row(0);
		}
		else {
			return null;
		}
	}
	
	public function get_friend_update_data($userid) {
		$sql = "SELECT count(inviter) as fans_count FROM friend WHERE invitee = $userid ";
		$query = $this->db->query ( $sql );
		if ($query->num_rows() > 0) {
			return $query->row(0);
		}
		else {
			return null;
		}
	}
}
